package com.bestcem.xm.user.util.business.mapstract;

import com.bestcem.xm.common.core.uitls.GrpcDateUtil;
import com.google.protobuf.Timestamp;
import org.apache.commons.lang3.math.NumberUtils;
import org.mapstruct.Named;

import java.util.Date;

/**
 * mapstract转换策略
 *
 * @author wangyunyun <yunyun.wang@idiaoyan.com>
 * @version v1.0
 * @date 2022/6/16 15:10
 */
public interface TransformStrategy {

    @Named(TransformStrategyConstant.BOOLEAN_TO_INTEGER)
    default Integer booleanToInteger(Boolean value) {
        return value != null && value ? NumberUtils.INTEGER_ONE : NumberUtils.INTEGER_ZERO;
    }

    @Named(TransformStrategyConstant.INTEGER_TO_BOOLEAN)
    default Boolean integerToBoolean(Integer value) {
        return !(value == null || NumberUtils.INTEGER_ZERO.equals(value));
    }

    @Named(TransformStrategyConstant.GRPC_TIMESTAMP_TO_DATE)
    default Date grpcTimestampToDate(Timestamp value) {
        return GrpcDateUtil.getDate(value);
    }

    @Named(TransformStrategyConstant.DATE_TO_GRPC_TIMESTAMP)
    default Timestamp dateToGrpcTimestamp(Date value) {
        return GrpcDateUtil.getTimestamp(value);
    }

    @Named(TransformStrategyConstant.STRING_ARR_TO_STRING)
    default Timestamp stringArrToString(Date value) {
        return GrpcDateUtil.getTimestamp(value);
    }
}
